package com.fr71.project.dm.controller;

import javax.servlet.http.HttpServletResponse;

import com.fr71.framework.aspectj.lang.annotation.Log;
import com.fr71.framework.aspectj.lang.enums.BusinessType;
import com.fr71.framework.web.controller.BaseController;
import com.fr71.framework.web.domain.AjaxResult;
import com.fr71.framework.web.page.TableDataInfo;
import com.fr71.common.utils.poi.ExcelUtil;
import com.fr71.project.dm.domain.AuthLog;
import com.fr71.project.dm.service.IAuthLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 开发者：https://github.com/devzwy
 * 创建时间：2023-08-07
 * 类描述：鉴权日志Controller
 */
@RestController
@RequestMapping("/dm/auth_log")
public class AuthLogController extends BaseController {
    
    @Autowired
    private IAuthLogService authLogService;

    /**
     * 查询鉴权日志列表
     */
    @PreAuthorize("@ss.hasPermi('dm:auth_log:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuthLog authLog) {
        startPage();
        List<AuthLog> list = authLogService.selectAuthLogList(authLog);
        return getDataTable(list);
    }

    /**
     * 导出鉴权日志列表
     */
    @PreAuthorize("@ss.hasPermi('dm:auth_log:export')")
    @Log(title = "鉴权日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuthLog authLog) {
        List<AuthLog> list = authLogService.selectAuthLogList(authLog);
        ExcelUtil<AuthLog> util = new ExcelUtil<AuthLog>(AuthLog.class);
        util.exportExcel(response, list, "鉴权日志数据");
    }

    /**
     * 获取鉴权日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('dm:auth_log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(authLogService.selectAuthLogById(id));
    }

    /**
     * 新增鉴权日志
     */
    @PreAuthorize("@ss.hasPermi('dm:auth_log:add')")
    @Log(title = "鉴权日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuthLog authLog) {
        return toAjax(authLogService.insertAuthLog(authLog));
    }

    /**
     * 修改鉴权日志
     */
    @PreAuthorize("@ss.hasPermi('dm:auth_log:edit')")
    @Log(title = "鉴权日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuthLog authLog) {
        return toAjax(authLogService.updateAuthLog(authLog));
    }

    /**
     * 删除鉴权日志
     */
    @PreAuthorize("@ss.hasPermi('dm:auth_log:remove')")
    @Log(title = "鉴权日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(authLogService.deleteAuthLogByIds(ids));
    }
}